/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package accountManagement.sessionbean;


import javax.ejb.LocalBean;
import accountManagement.entity.Employee;
import accountManagement.entity.Salesman;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Wei Haoyang
 */
@Stateless
@LocalBean
public class SalesmanManager {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @PersistenceContext
    private EntityManager em;
    
    public Salesman getSalesmanById(Long EmployeeId)
    {
        return em.find(Salesman.class, EmployeeId);
    }
    
    public void addSalesman(Salesman salesmanEntity)
    {
        em.persist(salesmanEntity);
    }
    public void editSalesmanEntity(Salesman salesmanEntity)
    {
        em.merge(salesmanEntity);
    }
    

    public void removeSalesmanEntity(Long salesmanId)
    {
        Salesman salesmanEntity = em.find(Salesman.class, salesmanId);
        em.remove(salesmanEntity);
    }
    
    public List<Employee> getAllSalesman(){
        Query query = em.createQuery("SELECT s1 FROM SalesmanEntity s1");
        return query.getResultList();
    }
    

}
